package com.xnyzc.lhy.mis.mapper.vehicle;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xnyzc.lhy.mis.entity.result.cms.veh.VehicleSeries;
import com.xnyzc.lhy.mis.entity.result.cms.veh.VehicleTypeSeries;
import com.xnyzc.lhy.mis.entity.vehicle.OaVehicleSeries;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 用车类型-车系关联表 Mapper 接口
 * </p>
 *
 * @author liuju
 * @since 2019-08-23
 */
public interface OaVehicleSeriesMapper extends BaseMapper<OaVehicleSeries> {


    @Select({
            "<script> " +
             "SELECT " +
                    "oa_vehicle_series.linked_id," +
                    "oa_vehicle_series.vehicle_type," +
                    "oa_vehicle_series.code," +
                    "oa_vehicle_series.veh_seats_number," +
                    "oa_sys_dict.label " +
                    "FROM " +
                    "oa_vehicle_series, " +
                    "oa_sys_dict " +
                    "WHERE " +
                    "oa_vehicle_series.deleted = 0  " +
                    "AND oa_sys_dict.deleted = 0  " +
                    "AND oa_sys_dict.type = 'require_level' " +
                    "AND oa_vehicle_series.vehicle_type = oa_sys_dict.value " +
                    "<if test='vehicle_type.length() != 0' >"+
                       "AND oa_vehicle_series.vehicle_type = #{vehicle_type} "+
                    "</if> " +
                    "<if test='code.size() != 0' >"+
                    "AND oa_vehicle_series.code in " +
                    "<foreach collection='code' item='item'  index='index' open='(' separator=',' close=')'>" +
                      "#{item}   " +
                    "</foreach>   " +
                    "</if> " +
                    "ORDER BY oa_vehicle_series.create_time DESC  " +
            "</script>"
    })
    List<VehicleSeries> getVehicleSeriesList(IPage iPage,@Param("vehicle_type") String vehicleType,@Param("code") List<String> code);

    @Update("update " +
            "oa_vehicle_series " +
            "set code =#{code},  " +
            "veh_seats_number =#{veh_seats_number},  " +
            "vehicle_type =#{vehicle_type}  " +
            "where linked_id=#{linked_id}")
    int result(@Param("code")String code, @Param("veh_seats_number")Integer vehSeatsNumber,@Param("vehicle_type")String vehicleType,@Param("linked_id")Long linkedId);
}
